//
//  WithdrawViewController.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-9.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddWithdrawViewController.h"
#import "JddUserProfile.h"

@interface JddWithdrawViewController ()

@end

@implementation JddWithdrawViewController

@synthesize moneytext;
@synthesize banklabel;
@synthesize bankcardlabel;
@synthesize moneylabel;
@synthesize password;


SHARED_VIEW_CONTROLLER_IMPLEMENT(JddWithdrawViewController);

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(IBAction)textFieldDoneEditing:(id)sender{
    [sender resignFirstResponder];
}

-(IBAction)backgroundClick:(id)sender{
    [moneytext resignFirstResponder];
    [password resignFirstResponder];
}

-(void)QueryWithDrawOperationResult:(NSData*)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if(result){
        if ([JddDataParser parseBuyResult:result]) {
             [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
        }else {
            [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
           
        }
    }
}

-(IBAction)commitData:(id)sender{
    if ([moneytext.text intValue]<20) {
        [JddCommonFunction messageBoxWithMessage:@"提款金额至少为20彩豆"];
        return;
    }
    if(!password.text || [password.text length]<6){
        [JddCommonFunction messageBoxWithMessage:@"请输入正确的提款密码，最少6位"];
        return;
    }
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
    JddQueryWithDrawOperation *operation = [[JddQueryWithDrawOperation alloc] init];
    operation.delegate = self;
    operation.Money =moneytext.text;
    operation.pwd = password.text;
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    [self.navigationItem setTitle:PAGE_WITHDRAW];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_WITHDRAW];
        customLab.textAlignment = NSTextAlignmentCenter;
        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;
        
        //self.navigationItem.hidesBackButton = YES;

}

- (void)QueryUserInfoOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        if (![JddDataParser parseUserInfoResult:result]) {
            [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
        }else {
            self.banklabel.text = [JddUserProfile sharedInstance].BankName;
            self.bankcardlabel.text = [JddUserProfile sharedInstance].BankCardNumber;
            self.moneylabel.text = [NSString stringWithFormat:@"%@彩豆", [JddUserProfile sharedInstance].balance];
            
        }
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"TiXian"];

    moneytext.text = @"";
    password.text = @"";
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"TiXian"];
    [MobClick event:@"tiKuanShenQing"];

    self.banklabel.text = @"";
    self.bankcardlabel.text = @"";
    self.moneylabel.text = @"";
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
    JddQueryUserInfoOperation *operation = [[JddQueryUserInfoOperation alloc] init];
    operation.delegate = self;
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    
    
}

-(IBAction)urlSelect:(id)sender{

    NSString *URLString = @"http://mobile.jiangduoduo.com";

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLString]];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
